package com.jyw.business.ast.domain.dto.web;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jyw.business.ast.constant.AstRelationConstant;
import com.jyw.business.ast.domain.AstDealRelation;
import com.jyw.business.ast.domain.AstDispose;
import com.jyw.common.utils.DateUtils;
import com.jyw.common.utils.SecurityUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
@ApiModel("处置申请")
public class AstDisposeDto {

    /** 借用原因 */
    @ApiModelProperty("处置原因")
    private String reason;

    @ApiModelProperty("借用资产集合")
    private List<DisposeAstDto> astList;

    public AstDispose buildDispose() {
        AstDispose dispose = new AstDispose();
        dispose.setReason(getReason());
        dispose.setCreateUser(SecurityUtils.getUserId());
        dispose.setCreateTime(DateUtils.getNowDate());
        dispose.setAuditState("0");
        return dispose;
    }

    public List<AstDealRelation> buildRelation(AstDispose dispose) {
        return getAstList().stream().map(data -> {
            AstDealRelation relation = new AstDealRelation();
            relation.setType(AstRelationConstant.DISPOSE);
            relation.setBusinessId(dispose.getId());
            relation.setAstId(data.getId());
            relation.setDispose(data.getDispose());
            return relation;
        }).collect(Collectors.toList());
    }
}
